package asteroids.model.programs.parsing.expressions;

import java.util.List;
import java.util.Map;

import asteroids.model.programs.parsing.types.DoubleLiteral;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of arithmetic expressions.
 * An arithmetic expression involves a single arithmetic operator applied to a left-hand operand and a right-hand operand.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public abstract class ArithmeticExpr extends BinOpExpr {

	public ArithmeticExpr(Expression e1, Expression e2,int line, int column) {
		super(e1, e2, line, column);
	}

	@Override
	public  List<String> getTypeCheckErrors(List<String> errors, Map<String, Type> globals) {
		errors = getLeftOperand().getTypeCheckErrors(errors, globals);
		errors = getRightOperand().getTypeCheckErrors(errors, globals);
		try{
		if(getLeftOperand().eval(null, globals).getClass()!=DoubleLiteral.class ||
				getRightOperand().eval(null, globals).getClass()!=DoubleLiteral.class){
			errors.add(getLine()+"-"+getColumn()+": Only arithmetic operations on doubles!");
		}
		}
		catch(NullPointerException e){
			errors.add("No valid arithmetic expression.");
		}
		return errors;
	}
}
